import request from '@/utils/request'
import type { ApiResponse, User } from '@/types/api'

// 获取所有用户
export function getAllUsers() {
  return request<ApiResponse<User[]>>({
    url: '/api/user/list',
    method: 'get'
  })
}

// 获取某车间所有用户
export function getUsersByGroup(groupId: number) {
  return request<ApiResponse<User[]>>({
    url: '/api/user/listByGroup',
    method: 'get',
    params: { id: groupId }
  })
}

// 创建用户
export interface CreateUserData {
  username: string
  password: string
  realName: string
  groupId: number | string
  phone: string
  remark: string
}

export function createUser(data: CreateUserData) {
  return request<ApiResponse<User>>({
    url: '/api/user/create',
    method: 'post',
    data
  })
}

// 更新用户
export function updateUser(id: number, data: Partial<CreateUserData>) {
  return request<ApiResponse<User>>({
    url: `/api/user/${id}`,
    method: 'put',
    data
  })
}

// 删除用户
export function deleteUser(id: number) {
  return request<ApiResponse<null>>({
    url: `/api/user/${id}`,
    method: 'delete'
  })
}

// 重置用户密码
export function resetUserPassword(userId: number, data: { newPassword: string }) {
  return request<ApiResponse<null>>({
    url: `/api/user/${userId}/password`,
    method: 'post',
    data
  })
}

// 获取用户详情
export function getEmployee(id: number | string) {
  return request<ApiResponse<User>>({
    url: `/api/user/${id}`,
    method: 'get'
  })
} 